namespace CuaHangBanGiay.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.DonHangs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ngay = c.DateTime(nullable: false),
                        tongtien = c.Int(nullable: false),
                        dathanhtoan = c.Boolean(nullable: false),
                        dagiaohang = c.Boolean(nullable: false),
                        diachi_nguoinhan = c.String(),
                        ten_nguoinhan = c.String(),
                        sdt_nguoinhan = c.String(),
                        tennv = c.String(),
                        active = c.Boolean(nullable: false),
                        nguoidung_id = c.Int(),
                        khachhang_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.NhanViens", t => t.nguoidung_id)
                .ForeignKey("dbo.KhachHangs", t => t.khachhang_id)
                .Index(t => t.nguoidung_id)
                .Index(t => t.khachhang_id);
            
            CreateTable(
                "dbo.ChiTiet_DonHang",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        soluong = c.Int(nullable: false),
                        dongia = c.Int(nullable: false),
                        donhang_id = c.Int(),
                        sanpham_tag_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.DonHangs", t => t.donhang_id)
                .ForeignKey("dbo.ChiTietSP", t => t.sanpham_tag_id)
                .Index(t => t.donhang_id)
                .Index(t => t.sanpham_tag_id);
            
            CreateTable(
                "dbo.ChiTietSP",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        soluong = c.Int(nullable: false),
                        active = c.Boolean(nullable: false),
                        kichthuoc_id = c.Int(),
                        mausac_id = c.Int(),
                        sanpham_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.KichThuocs", t => t.kichthuoc_id)
                .ForeignKey("dbo.MauSacs", t => t.mausac_id)
                .ForeignKey("dbo.SanPhams", t => t.sanpham_id)
                .Index(t => t.kichthuoc_id)
                .Index(t => t.mausac_id)
                .Index(t => t.sanpham_id);
            
            CreateTable(
                "dbo.ChiTiet_NhapHang",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        soluong = c.Int(nullable: false),
                        dongia = c.Int(nullable: false),
                        nhaphang_id = c.Int(),
                        sanpham_tag_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.NhapHangs", t => t.nhaphang_id)
                .ForeignKey("dbo.ChiTietSP", t => t.sanpham_tag_id)
                .Index(t => t.nhaphang_id)
                .Index(t => t.sanpham_tag_id);
            
            CreateTable(
                "dbo.NhapHangs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ngay = c.DateTime(nullable: false),
                        tongtien = c.Int(nullable: false),
                        thanhtoan = c.Int(nullable: false),
                        ten_nhanvien = c.String(),
                        ten_nhacungcap = c.String(),
                        active = c.Boolean(nullable: false),
                        nhacc_id = c.Int(),
                        nhanvien_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.NhaCCs", t => t.nhacc_id)
                .ForeignKey("dbo.NhanViens", t => t.nhanvien_id)
                .Index(t => t.nhacc_id)
                .Index(t => t.nhanvien_id);
            
            CreateTable(
                "dbo.NhaCCs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ten_ncc = c.String(),
                        diachi_ncc = c.String(),
                        sdt_ncc = c.String(),
                        active = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.NhanViens",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tendangnhap = c.String(),
                        tendaydu = c.String(),
                        email = c.String(),
                        matkhau = c.String(),
                        active = c.Boolean(nullable: false),
                        nhomnhanvien_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.NhomNhanViens", t => t.nhomnhanvien_id)
                .Index(t => t.nhomnhanvien_id);
            
            CreateTable(
                "dbo.NhomNhanViens",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tennhom = c.String(),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.PhanQuyens",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tenquyen = c.String(),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.PhanHois",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ten = c.String(),
                        noidung = c.String(),
                        ngay = c.DateTime(nullable: false),
                        active = c.Boolean(nullable: false),
                        nhanvien_id = c.Int(),
                        khachhang_id = c.Int(),
                        topic_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.NhanViens", t => t.nhanvien_id)
                .ForeignKey("dbo.KhachHangs", t => t.khachhang_id)
                .ForeignKey("dbo.Topics", t => t.topic_id)
                .Index(t => t.nhanvien_id)
                .Index(t => t.khachhang_id)
                .Index(t => t.topic_id);
            
            CreateTable(
                "dbo.KhachHangs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tendangnhap = c.String(),
                        tendaydu = c.String(),
                        matkhau = c.String(),
                        diachi = c.String(),
                        email = c.String(),
                        sdt = c.String(),
                        active = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.Topics",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ten = c.String(),
                        noidung = c.String(),
                        ngay = c.DateTime(nullable: false),
                        active = c.Boolean(nullable: false),
                        nguoitao_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.KhachHangs", t => t.nguoitao_id)
                .Index(t => t.nguoitao_id);
            
            CreateTable(
                "dbo.TonKhoes",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ngay = c.DateTime(nullable: false),
                        soluongton = c.Int(nullable: false),
                        sanpham_tag_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.ChiTietSP", t => t.sanpham_tag_id)
                .Index(t => t.sanpham_tag_id);
            
            CreateTable(
                "dbo.KichThuocs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        giatri = c.String(),
                        active = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.MauSacs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        giatri = c.String(),
                        active = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.SanPhams",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        masp = c.String(),
                        ten = c.String(),
                        mota = c.String(),
                        gia = c.Int(nullable: false),
                        active = c.Boolean(nullable: false),
                        hangsx_id = c.Int(),
                        nhomsanpham_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.HangSXes", t => t.hangsx_id)
                .ForeignKey("dbo.NhomSanPhams", t => t.nhomsanpham_id)
                .Index(t => t.hangsx_id)
                .Index(t => t.nhomsanpham_id);
            
            CreateTable(
                "dbo.HinhAnhs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        duongdan = c.String(),
                        SanPham_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.SanPhams", t => t.SanPham_id)
                .Index(t => t.SanPham_id);
            
            CreateTable(
                "dbo.HangSXes",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tenhsx = c.String(),
                        active = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.NhomSanPhams",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        ten = c.String(),
                        mota = c.String(),
                        active = c.Boolean(nullable: false),
                        nhomcha_id = c.Int(),
                    })
                .PrimaryKey(t => t.id)
                .ForeignKey("dbo.NhomSanPhams", t => t.nhomcha_id)
                .Index(t => t.nhomcha_id);
            
            CreateTable(
                "dbo.ChiPhiVCs",
                c => new
                    {
                        id = c.Int(nullable: false, identity: true),
                        tentinh = c.String(),
                        chiphivc = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.id);
            
            CreateTable(
                "dbo.PhanQuyenNhomNhanViens",
                c => new
                    {
                        PhanQuyen_id = c.Int(nullable: false),
                        NhomNhanVien_id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.PhanQuyen_id, t.NhomNhanVien_id })
                .ForeignKey("dbo.PhanQuyens", t => t.PhanQuyen_id, cascadeDelete: true)
                .ForeignKey("dbo.NhomNhanViens", t => t.NhomNhanVien_id, cascadeDelete: true)
                .Index(t => t.PhanQuyen_id)
                .Index(t => t.NhomNhanVien_id);
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.PhanQuyenNhomNhanViens", new[] { "NhomNhanVien_id" });
            DropIndex("dbo.PhanQuyenNhomNhanViens", new[] { "PhanQuyen_id" });
            DropIndex("dbo.NhomSanPhams", new[] { "nhomcha_id" });
            DropIndex("dbo.HinhAnhs", new[] { "SanPham_id" });
            DropIndex("dbo.SanPhams", new[] { "nhomsanpham_id" });
            DropIndex("dbo.SanPhams", new[] { "hangsx_id" });
            DropIndex("dbo.TonKhoes", new[] { "sanpham_tag_id" });
            DropIndex("dbo.Topics", new[] { "nguoitao_id" });
            DropIndex("dbo.PhanHois", new[] { "topic_id" });
            DropIndex("dbo.PhanHois", new[] { "khachhang_id" });
            DropIndex("dbo.PhanHois", new[] { "nhanvien_id" });
            DropIndex("dbo.NhanViens", new[] { "nhomnhanvien_id" });
            DropIndex("dbo.NhapHangs", new[] { "nhanvien_id" });
            DropIndex("dbo.NhapHangs", new[] { "nhacc_id" });
            DropIndex("dbo.ChiTiet_NhapHang", new[] { "sanpham_tag_id" });
            DropIndex("dbo.ChiTiet_NhapHang", new[] { "nhaphang_id" });
            DropIndex("dbo.ChiTietSP", new[] { "sanpham_id" });
            DropIndex("dbo.ChiTietSP", new[] { "mausac_id" });
            DropIndex("dbo.ChiTietSP", new[] { "kichthuoc_id" });
            DropIndex("dbo.ChiTiet_DonHang", new[] { "sanpham_tag_id" });
            DropIndex("dbo.ChiTiet_DonHang", new[] { "donhang_id" });
            DropIndex("dbo.DonHangs", new[] { "khachhang_id" });
            DropIndex("dbo.DonHangs", new[] { "nguoidung_id" });
            DropForeignKey("dbo.PhanQuyenNhomNhanViens", "NhomNhanVien_id", "dbo.NhomNhanViens");
            DropForeignKey("dbo.PhanQuyenNhomNhanViens", "PhanQuyen_id", "dbo.PhanQuyens");
            DropForeignKey("dbo.NhomSanPhams", "nhomcha_id", "dbo.NhomSanPhams");
            DropForeignKey("dbo.HinhAnhs", "SanPham_id", "dbo.SanPhams");
            DropForeignKey("dbo.SanPhams", "nhomsanpham_id", "dbo.NhomSanPhams");
            DropForeignKey("dbo.SanPhams", "hangsx_id", "dbo.HangSXes");
            DropForeignKey("dbo.TonKhoes", "sanpham_tag_id", "dbo.ChiTietSP");
            DropForeignKey("dbo.Topics", "nguoitao_id", "dbo.KhachHangs");
            DropForeignKey("dbo.PhanHois", "topic_id", "dbo.Topics");
            DropForeignKey("dbo.PhanHois", "khachhang_id", "dbo.KhachHangs");
            DropForeignKey("dbo.PhanHois", "nhanvien_id", "dbo.NhanViens");
            DropForeignKey("dbo.NhanViens", "nhomnhanvien_id", "dbo.NhomNhanViens");
            DropForeignKey("dbo.NhapHangs", "nhanvien_id", "dbo.NhanViens");
            DropForeignKey("dbo.NhapHangs", "nhacc_id", "dbo.NhaCCs");
            DropForeignKey("dbo.ChiTiet_NhapHang", "sanpham_tag_id", "dbo.ChiTietSP");
            DropForeignKey("dbo.ChiTiet_NhapHang", "nhaphang_id", "dbo.NhapHangs");
            DropForeignKey("dbo.ChiTietSP", "sanpham_id", "dbo.SanPhams");
            DropForeignKey("dbo.ChiTietSP", "mausac_id", "dbo.MauSacs");
            DropForeignKey("dbo.ChiTietSP", "kichthuoc_id", "dbo.KichThuocs");
            DropForeignKey("dbo.ChiTiet_DonHang", "sanpham_tag_id", "dbo.ChiTietSP");
            DropForeignKey("dbo.ChiTiet_DonHang", "donhang_id", "dbo.DonHangs");
            DropForeignKey("dbo.DonHangs", "khachhang_id", "dbo.KhachHangs");
            DropForeignKey("dbo.DonHangs", "nguoidung_id", "dbo.NhanViens");
            DropTable("dbo.PhanQuyenNhomNhanViens");
            DropTable("dbo.ChiPhiVCs");
            DropTable("dbo.NhomSanPhams");
            DropTable("dbo.HangSXes");
            DropTable("dbo.HinhAnhs");
            DropTable("dbo.SanPhams");
            DropTable("dbo.MauSacs");
            DropTable("dbo.KichThuocs");
            DropTable("dbo.TonKhoes");
            DropTable("dbo.Topics");
            DropTable("dbo.KhachHangs");
            DropTable("dbo.PhanHois");
            DropTable("dbo.PhanQuyens");
            DropTable("dbo.NhomNhanViens");
            DropTable("dbo.NhanViens");
            DropTable("dbo.NhaCCs");
            DropTable("dbo.NhapHangs");
            DropTable("dbo.ChiTiet_NhapHang");
            DropTable("dbo.ChiTietSP");
            DropTable("dbo.ChiTiet_DonHang");
            DropTable("dbo.DonHangs");
        }
    }
}
